package cate.common.table.farm.udgpalace.row;

import cate.common.annotation.SplitParse;
import cate.common.table.EExcelNoteField;
import cate.common.table.EExcelRowClass;
import cate.common.table.ERow;
import cate.common.table.item.rune.SkillGroupList;
import cate.common.util.SplitParser;
import cate.common.util.random.RWItem;
import cate.common.util.random.RWList;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

@EExcelRowClass(IDTitle = "事件组ID")
public class UdgPalaceEventRow extends ERow {
    @EExcelNoteField(fieldName = "各事件概率")
    private String eventGroupStr;

    @EExcelNoteField(fieldName = "掉落类型参数")
    private String dropStr;

    @EExcelNoteField(fieldName = "地宫商店ID")
    private String shopGroupStr;

    @EExcelNoteField(fieldName = "趣味问答分组")
    private String questionGroupStr;

    @EExcelNoteField(fieldName = "神秘事件分组")
    private String mysteriousGroupStr;

    @EExcelNoteField(fieldName = "转盘组")
    private String turntableGroupStr;

    @EExcelNoteField(fieldName = "宝箱类型参数")
    private String boxGroupStr;

    public SkillGroupList eventGroup = new SkillGroupList();
    public SkillGroupList shopGroup = new SkillGroupList();
    public SkillGroupList questionGroup = new SkillGroupList();
    public SkillGroupList mysteriousGroup = new SkillGroupList();
    public SkillGroupList turntableGroup = new SkillGroupList();
    public ItemGroupList boxGroup;
    public ItemGroupList dropGroup;

    @Override
    public void decode() {
        eventGroup.parse(eventGroupStr);
        shopGroup.parse(shopGroupStr);
        questionGroup.parse(questionGroupStr);
        mysteriousGroup.parse(mysteriousGroupStr);
        turntableGroup.parse(turntableGroupStr);
        if (StringUtils.isNotBlank(boxGroupStr)) {
            boxGroup = ItemGroupList.build(boxGroupStr);
        }
        if (StringUtils.isNotBlank(dropStr)) {
            dropGroup = ItemGroupList.build(dropStr);
        }
    }

    public static final class ItemGroupList extends RWList<ItemGroupList.Item> {
        public static final class Item implements RWItem {
            @SplitParse(order = 0, note = "物品大类")
            public byte type;

            @SplitParse(order = 1, note = "模板ID")
            public int tid;

            @SplitParse(order = 2, defaultValue = "1", note = "数量")
            public int num;

            @SplitParse(order = 3, defaultValue = "100", note = "权重")
            public double weight;

            @Override
            public double getWeight() {
                return weight;
            }
        }

        public static ItemGroupList build(String config) {
            ItemGroupList list = new ItemGroupList();
            List<ItemGroupList.Item> l = SplitParser.parse(ItemGroupList.Item.class, config);
            list.setup(l);
            return list;
        }
    }
}
